home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part2 / 10116 < prev    next >
Encoding:
Text File  |  1996-08-05  |  3.6 KB  |  95 lines

  1. Path: newsfeed.internetmci.com!xmission!inteleNET!usenet
  2. From: chalain@mcr.net (Chalain)
  3. Newsgroups: comp.lang.c++
  4. Subject: Question about header files
  5. Date: 5 Mar 1996 01:22:37 GMT
  6. Organization: inteleNET Internet Services
  7. Message-ID: <4hg50t$924@vodka.intele.net>
  8. NNTP-Posting-Host: 206.29.210.159
  9. Mime-Version: 1.0
  10. X-Newsreader: WinVN 0.93.14
  11.  
  12. Anyone feeling generous?  I have a question that wants an essay-style
  13. answer....
  14.  
  15. First, the scene: I have Symantec C++ 6.1, nice compiler, no manuals.  
  16. Got
  17. just the CD, which has manuals on it, but they are reference manuals and
  18. assume that I am fluent in C/C++ grammar.  The problem is that I are not.
  19.  
  20. A beginning C++ book I have says to do this (with Borland Turbo C++):
  21.  
  22. In the main file (main.cpp), put the line
  23.  
  24. #include "myheader.h";
  25.  
  26. and in myheader.cpp, put the line
  27.  
  28. #include "myheader.h";
  29.  
  30. From this, I assume that the compiler, upon opening a *.h file, will
  31. check for a *.c or *.cpp file of the same name, yes?  
  32.  
  33. This confuses me just a little bit.  However, it gets worse.
  34.  
  35. I have a main C++ file called, appropriately enough, MAINFILE.CPP.  It
  36. uses some homemade graphics functions that I have written myself.  These
  37. are in a file called MYGRAPH.CPP, and their prototypes and structures
  38. are in a file called MYGRAPH.H.  Now, here is where it gets fun.
  39.  
  40. I assign a pointer to the mode 0x13 video memory with the line
  41.  
  42. unsigned char far *video_buffer = (unsigned char far *)0xA0000000L;
  43.  
  44. I would *really* like to put this line either in the header file or in
  45. the code file for graphics, but if I do I can't get access to the pointer
  46. in MAINFILE or any of its other dependents.  Right now I'm defining it
  47. globally in MAINFILE.  Crude, but effective.  Is there a more elegant way
  48. to put this pointer in the graphics files yet still give it global scope?
  49. Be aware that I am using Symantec C++ and am compiling from the DOS 
  50. prompt, 
  51. so there aren't any IDE options or project resources that I can add or
  52. tinker with.
  53.  
  54. Secondly, I have an extension of my set of graphics function to cope with
  55. PCX graphic files.  These functions are in PCXFILE.H and PCXFILE.CPP.
  56. I would like to include these files as is, but right now the code just
  57. will not compile.  I either get "identifier already defined" at compile
  58. time if I put #include MYGRAPH and #include PCXFILE in MAINFILE or 
  59. "unknown
  60. identifier" at link time if I put #include PCXFILE inside MYGRAPH.H.  
  61. Right
  62. now my work around is to case and paste the entire PCX function set into 
  63. the
  64. MYGRAPH files... an inelegant and poorly portable solution if ever there 
  65. was
  66. one!
  67.  
  68. So here are my questions:
  69.  
  70. Can my graphics file be written so that it is just "plugs in" without
  71. having to define global pointers in the main file?  (Can I define
  72. identifiers there that will be used in the MAINFILE?)
  73.  
  74. Can my PCXGRAPH file be written to "plug in" to the graphics file, such
  75. that it does not require its own set of graphics functions (and pointers,
  76. etc) yet MYGRAPH works with no modification with or without it?  (Meaning
  77. that it will inherit access to MYGRAPH's functions, yet still pass
  78. functions, identifiers, and #defines up to MAINFILE?)
  79.  
  80. Will Clint get out of the hospital in time to stop the wedding?
  81.  
  82. Can someone explain to me how header files work in the "general case?"
  83. Ie., what happens when you #include a header file, what dependencies are
  84. checked, what gets compiled first, what happens if a header file 
  85. #includes another header file, et cetera?  I would be most grateful.
  86.  
  87. Thank you very much in advance for any and all help given!
  88.  
  89. Chalain
  90.  
  91. P.S. For the sake of newbies like myself, feel free to reply to the
  92. newsgroup.  For my sake, however, please reply via e-mail.  My usenet
  93. priviledges are very limited.
  94.  
  95.